package FloorComponents;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;

import javax.swing.JFrame;
import javax.swing.JLabel;

import org.jhotdraw.figures.RectangleFigure;
import org.jhotdraw.framework.HandleEnumeration;
import org.jhotdraw.standard.AbstractFigure;

import DimensionTools.DimensionTool;
import DimensionTools.WindowDimensionTool;

public class Window extends RectangleFigure implements FloorPlanComponents {
	//WindowDimensionTool _dTool = new WindowDimensionTool();

	RectangleFigure _rect1 = new RectangleFigure();
	RectangleFigure _rect2 = new RectangleFigure();


	@Override
	public void create() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void delete() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void adjust(int topX, int topY, int botX, int botY) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void rotate() {
		// TODO Auto-generated method stub
		
	}
//	public void displayBox(Point origin, Point corner, Point origin2, Point corner2){
//		_rect1.displayBox(origin, corner);
//		_rect2.displayBox(origin2, corner2);
//	}
//	@Override
//	public Rectangle displayBox() {
//		// TODO Auto-generated method stub
//		return null;
//	}
//
//	@Override
//	public HandleEnumeration handles() {
//		// TODO Auto-generated method stub
//		return null;
//	}
//	
	@Override
	public void drawBackground(Graphics g) {
		Rectangle r = displayBox();
		
		
		// limits the fill to certain height and width
		
		if (r.height>10 && (r.width > r.height)){
			System.out.println("enters");
			displayBox(new Point(r.x,r.y),new Point(r.x+r.width,r.y+10));
			r = displayBox();
		}
		if (r.width>10 && (r.width <= r.height)){
			System.out.println("enters");
			displayBox(new Point(r.x,r.y),new Point(r.x+10,r.y+r.height));
			r = displayBox();
		}
		
		//int[] xpoints = new int[]{r.width/2+r.x, r.x, r.x+r.width};
		//int[] ypoints = new int[]{r.y, r.y+r.height, r.y+r.height};
		g.setColor(Color.CYAN);
		g.fillRect(r.x, r.y, r.width, r.height);
		;
		
	}

	@Override
	public void drawFrame(Graphics g) {
		Rectangle r = displayBox();
		System.out.println("x_"+ r.x + " y " + r.y);
		//int[] xpoints = new int[]{r.width/2+r.x, r.x, r.x+r.width};
		//int[] ypoints = new int[]{r.y, r.y+r.height, r.y+r.height};
		//g.drawPolygon(xpoints, ypoints, 3);
		
		
		// orients line
		if (r.width > r.height){
			
			//fixes width and height, permanent consider editing
			
			
			System.out.println(r.height);
			if (r.height>10){
				
				displayBox(new Point(r.x,r.y),new Point(r.x+r.width,r.y+10));
				r = displayBox();
			}
			
		g.drawRect(r.x, r.y, r.width, r.height);
		g.drawLine(r.x, r.y+r.height/2, r.x+r.width, r.y+r.height/2);
		}
		else if(r.width <= r.height){
			
			
			
			// 
			if (r.width>10){
				
				displayBox(new Point(r.x,r.y),new Point(r.x+10,r.y+r.height));
				}
			
			g.drawRect(r.x, r.y, r.width, r.height);
			g.drawLine(r.x+r.width/2, r.y, r.x+r.width/2, r.y+r.height);
			
		}
		}

	@Override
	public void openDimensionTool(DimensionableFigure parent) {
		WindowDimensionTool _dt =new WindowDimensionTool(parent);
		_dt.openWindow();
		
		//temp fix
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
	
		
	}

	
		
	
}